﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jzb.ConsoleApp
{
    class Calculator
    {
        //定义属性、变量
        //变量做为内部访问
        int _value = 0;//变量
        public int Value
        {
            get { return _value; }
            set
            {
                if (_value == value) return;
                _value = value;
            }
        }
        public int MyProperty { get; set; }
        public int MyProperty_1 { get; }// 只有get没有set，表示这个属性是只读
        public int MyProperty_2 { get; private set; }
        //public int MyProperty_2 { set; }// 不允许只写不读

        // 类中定义的方法
        public int Add(int a1, int a2)
        {
            //int a = 1, b = 2;
            int c = a1 + a2;
            MyProperty_2 = 111;
            return c;
        }
        public void Add_2(int a1, int a2, out int result)
        {
            result = a1 + a2;
            a1 = 100;
        }
        public void Add_3(int a1, int a2, ref int result)
        {
            result = a1 + a2;
        }

        public string Test()
        {
            return "Hello";
        }

        public void Calc(Location location)
        {
            location.X = 666;
        }
        public void Calc(StructValue structValue)
        {
            structValue.X = 888;
        }
        public StructValue StructValue { get; set; }

        public Location Location { get; set; }


        //默认的构造函数
        //public Calculator()
        //{
        //}

        // 无参构造函数
        public Calculator():this(0)//继承自有参的构造函数 会跳到下面的方法 Value=0了
        {
            //Value = 0;
            StructValue = new StructValue(1, 2);
            Location = new Location(2,4);
        }
        // 有参构造函数
        public Calculator(int a1)
        {
            Value = a1;
            //Value = Add(1, 2);
            //this.Value = 100;
        }
    }
}
